package com.glela.test;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import org.apache.commons.collections4.MapUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.glela.order.model.AfterSales;
import com.glela.order.service.AfterSalesService;

public class ValidationAfterSale implements Serializable,Callable<List<Map<String, Object>>>{
	private static Logger logger = LoggerFactory.getLogger(ValidationAfterSale.class);
	private static final long serialVersionUID = -7234384399097001954L;
    private List<AfterSales> AfterSalesList;
    private AfterSalesService afterSalesService;
	 
	public ValidationAfterSale(List<AfterSales> afterSalesList,
			AfterSalesService afterSalesService) {
		super();
		AfterSalesList = afterSalesList;
		this.afterSalesService = afterSalesService;
	}

	public List<Map<String, Object>> call(){
		List<Map<String, Object>> result=new ArrayList<Map<String, Object>>();
			Map<String, Object> temp=null;
				//验证售后单
				for(AfterSales afterSales:AfterSalesList){
					temp=new HashMap<String, Object>();
					try {
						 temp=afterSalesService.validationAfterSales(afterSales);
						 logger.info("正在验证:"+afterSales.getOrderInfoSn());
					} catch (Exception e) {
						temp.put("1",afterSales.getCustomerServiceNumber());
						temp.put("2","售后单验证失败 请重新验证"+e.getMessage());
					}
					if(MapUtils.isNotEmpty(temp)){
						result.add(temp);
					}
				}
		return result;
	}
}
